/*
 * @Description:登录页面
 * @Author: admin
 * @Date: 2021-06-11 16:59:03
 * @LastEditors: admin
 * @LastEditTime: 2021-06-11 17:41:47
 */
import React from 'react'
import { createHashHistory } from 'history'
import { Form, Input, Button, Checkbox } from 'antd';
import './css/My.css';

class Login extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    }
  }
  render () {
    const history = createHashHistory();
    const onFinish = (values) => {
      // 表单校验成功
      console.log('Success:', values);
      // 向后台发送登录请求
      var name = values.username
      var pwd = values.password
      if (name === 'admin' && pwd === '123321') {
        alert("登录成功")
        window.sessionStorage.setItem('user', values)
        window.location.reload()
      } else {
        alert("登录失败")

      }
    };

    const onFinishFailed = (errorInfo) => {
      // 表单校验失败
      console.log('Failed:', errorInfo);
    };
    const layout = {
      labelCol: {
        span: 8,
      },
      wrapperCol: {
        span: 16,
      },
    };
    const tailLayout = {
      wrapperCol: {
        offset: 8,
        span: 16,
      },
    };
    return (
      <div>
        <h1>欢迎登录</h1>
        <Form
          {...layout}
          name="basic"
          initialValues={{
            remember: true,
          }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
        >
          <Form.Item
            label="用户名"
            name="username"
            rules={[
              {
                required: true,
                message: '请输入用户名',
              },
            ]}
          >
            <Input />
          </Form.Item>

          <Form.Item
            label="密码"
            name="password"
            rules={[
              {
                required: true,
                message: '请输入密码',
              },
            ]}
          >
            <Input.Password />
          </Form.Item>

          <Form.Item {...tailLayout} name="remember" valuePropName="checked">
            <Checkbox>记住账号</Checkbox>
          </Form.Item>

          <Form.Item {...tailLayout}>
            <Button type="primary" htmlType="submit">
              登录
        </Button>
          </Form.Item>
        </Form>
      </div>
    )
  }

}

export default Login
